package com.yizhiliulianta.auth.infra.service.impl;

import com.yizhiliulianta.auth.infra.entity.AuthUserPermission;
import com.yizhiliulianta.auth.infra.mapper.AuthUserPermissionDao;
import com.yizhiliulianta.auth.infra.service.AuthUserPermissionService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * (AuthUserPermission)表服务实现类
 *
 * @author makejava
 * @since 2024-06-12 18:55:48
 */
@Service("authUserPermissionService")
public class AuthUserPermissionServiceImpl implements AuthUserPermissionService {
    @Resource
    private AuthUserPermissionDao authUserPermissionDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public AuthUserPermission queryById(Integer id) {
        return this.authUserPermissionDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param authUserPermission 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<AuthUserPermission> queryByPage(AuthUserPermission authUserPermission, PageRequest pageRequest) {
        long total = this.authUserPermissionDao.count(authUserPermission);
        return new PageImpl<>(this.authUserPermissionDao.queryAllByLimit(authUserPermission, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param authUserPermission 实例对象
     * @return 实例对象
     */
    @Override
    public AuthUserPermission insert(AuthUserPermission authUserPermission) {
        this.authUserPermissionDao.insert(authUserPermission);
        return authUserPermission;
    }

    /**
     * 修改数据
     *
     * @param authUserPermission 实例对象
     * @return 实例对象
     */
    @Override
    public AuthUserPermission update(AuthUserPermission authUserPermission) {
        this.authUserPermissionDao.update(authUserPermission);
        return this.queryById(authUserPermission.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.authUserPermissionDao.deleteById(id) > 0;
    }
}
